<?php 
namespace Admin\Controller;
use Think\Controller\RestController;
class CenterController extends RestController{

	public function index()
	{

		// $id = $_SESSION['home']['id'];
		$list = M('user')->select();
		// $tou = $list[0]['t_img'];
		// $name = $list[0]['user'];
		// $this->assign('tou',$tou);		
		// $this->assign('name',$name);
		$this->assign('list',$list);	
		$this->display();
	}



	public function tou()
	{
		// dump($_FILES);
		$id = $_SESSION['home']['id'];
		// echo $id;
		// exit;
		$upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728 ;// 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Public/Uploads/tou/'; // 设置附件上传根目录
        $upload->savePath = ''; // 设置附件上传（子）目录
        // 上传文件
        $info = $upload->upload();
        // dump($info);
        // exit;
        //头像的路径拼接
        $ilist = $info['photo']['savepath'].$info['photo']['savename'];
        $ilist = "/Uploads/tou/".$ilist;
        if (M('user')->where(array('id'=>$id))->save(array('t_img'=>$ilist)) > 0) {
        	$this->success('上传成功!!!');
        }else{
        	$this->error('上传失败!!!');
        	exit;
        }

	}



	public function collect()
	{
		// dump($_GET);
		// exit;
		$id = $_GET['id'];
		$list = M('collect')->where(array('u_id'=>$id))->select();
		// dump($list);
		// exit;
		
		foreach ($list as $vn) {
			// echo $v['n_id'];
			// exit;
			$n_id .= "`id`="."'".$vn['n_id']."'"." or ";

		}
		$n_id = rtrim($n_id,'or ');
		// echo $n_id;
		// exit;
		// dump($l);
		// exit;
		// $n_id = $list[0]['n_id'];
		$data = M('news')->where("$n_id")->select();
		// dump($data);
		// exit;
		foreach ($data as $va) {
			// echo $v['n_id'];
			// exit;
			$a_id .= "`id`="."'".$va['a_id']."'"." or ";

		}
		$a_id = rtrim($a_id,'or ');
		// echo $a_id;
		// $admin = M('admin_user')->where("$a_id")->select();
		// dump($admin);
		// exit;
		// foreach ($admin as $v) {
		// 	$arr .= $v['name'];
		// 	// exit;
		// }
		// dump($arr);

		// exit;
		// $a_name = $admin[0]['name'];
		
		
		$this->assign('id',$id);
		$this->assign('data',$list);
		// $this->assign('admin',$admin);
		$this->assign('list',$data);
		$this->display();
	}





	public function reply()
	{
		// dump(I());
		// exit;
		$id = $_GET['id'];
		//得到用户反馈信息
		$r_list = M('reply')->where(array('n_id'=>$id))->select();
		// dump($r_list);
		// exit;
		
		//拿出新闻ID
		// $n_id = $r_list[0]['n_id'];
		$u_id = $r_list[0]['u_id'];
		// echo $u_id;
		// exit;
		// 得到用户资料
		$u_list = M('user')->where(array('id'=>$u_id))->select();

		// dump($u_list);
		// exit;
		//得到新闻信息
		$n_list = M('news')->where(array('id'=>$n_id))->select();
		// dump($n_list);
		// exit;
		$this->assign('r_list',$r_list);//反馈信息
		$this->assign('u_list',$u_list);
		$this->assign('n_list',$n_list);//新闻信息
		// $this->assign('r_list',$r_list);
		$this->display();
		
	}




	public function del()
	{
		// dump($_POST);
		// exit;
		// echo 'true';
		$id = $_POST['id'];
        // echo 'true';
        // exit;
    	if (M('reply')->where('id='.$id)->delete() >0) {
    		echo 'true';
    	}else{
    		echo 'false';
    	}
	}










}

